package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.consts.ErmsCodePrefix;
import com.sugon.dao.SpecialDevPressureContainerDao;
import com.sugon.entity.SpecialDevPressureContainerEntity;
import com.sugon.service.SpecialDevPressureContainerService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 特种设备-压力容器台账Service实现类
 *
 * @author sugon
 * @date 2021-09-08 16:30:40
 */
@Service("specialDevPressureContainerService")
public class SpecialDevPressureContainerServiceImpl implements SpecialDevPressureContainerService {
    @Autowired
    private SpecialDevPressureContainerDao specialDevPressureContainerDao;

    @Override
    public SpecialDevPressureContainerEntity queryObject(String id) {
        return specialDevPressureContainerDao.queryObject(id);
    }

    @Override
    public List<SpecialDevPressureContainerEntity> queryList(Map<String, Object> map) {
        return specialDevPressureContainerDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return specialDevPressureContainerDao.queryTotal(map);
    }

    @Override
    public String generateUniqueCode() {
        String lastestEquipmentCode = specialDevPressureContainerDao.getLastestEquipmentCode(ErmsCodePrefix.PRESSURE_CONTAINER_CODE_PREFIX);
        return com.sugon.modules.utils.StrUtil.increase(lastestEquipmentCode, ErmsCodePrefix.PRESSURE_CONTAINER_CODE_PREFIX, 5, 1);
    }

    @Override
    public int save(SpecialDevPressureContainerEntity specialDevPressureContainer) {
        specialDevPressureContainer.setId(RandomUtil.randomString(32));
        specialDevPressureContainer.setGmtCreate(DateUtil.date());
        specialDevPressureContainer.setCreateUser(ShiroUtils.getUserId());
        specialDevPressureContainer.setEquipmentCode(generateUniqueCode());
        return specialDevPressureContainerDao.save(specialDevPressureContainer);
    }

    @Override
    public int update(SpecialDevPressureContainerEntity specialDevPressureContainer) {
        specialDevPressureContainer.setGmtModified(DateUtil.date());
        specialDevPressureContainer.setUpdateUser(ShiroUtils.getUserId());
        return specialDevPressureContainerDao.update(specialDevPressureContainer);
    }

    @Override
    public int delete(String id) {
        return specialDevPressureContainerDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return specialDevPressureContainerDao.deleteBatch(ids);
    }
}
